package 力扣日常刷题.木23一月.第01天301;

import 力扣日常刷题.TreeNode;

/**
 * @author 帅小伙
 * @date 2022/3/1
 * @description
 */
public class Demo08树的子结构 {

    public boolean isSubStructure(TreeNode A, TreeNode B){
        return (A != null && B != null) && (recur(A,B)
                || isSubStructure(A.left,B)
                ||isSubStructure(A.right,B));
    }

    // 验证是否是子树
    boolean recur(TreeNode A, TreeNode B){
        if(B == null) return true;
        if(A == null || A.val != B.val) return false;
        return recur(A.left,B.left) && recur(A.right, B.right);
    }

}
